<template>
  <div class="dashboard-container">
    <aside class="aside-style">
      <el-row>
        <el-col :span="2">
          <el-button type="primary" icon="el-icon-circle-plus" size="mini" @click="addRecruitLevel">新增</el-button>
        </el-col>
      </el-row>
    </aside>
    <el-table
      :data="list"
      border
      style="width: 100%;margin-top:20px"
    >
      <el-table-column
        prop="level"
        label="招聘等级"
        align="center"
      />
      <el-table-column
        prop="deposit"
        label="定金"
        width="180"
        align="center"
      />
      <el-table-column
        prop="down_payment"
        label="首付款"
        width="180"
        align="center"
      />
      <el-table-column
        prop="final_payment"
        label="尾款"
        width="180"
        align="center"
      />
      <el-table-column
        label="操作"
        align="center"
      >
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="resetRecruitLevel(scope.row)">修改</el-button>
          <el-button type="text" size="mini" @click="deleteRecruitLevel(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <recruitLevelInfo ref="info" @reloadFun="reloadFun" />
  </div>

</template>

<script>
import { getRecruitLevelApi, deleteRecruitLevelApi } from '@/api/main'
import recruitLevelInfo from './components/recruit-level-info'
export default {
  components: {
    recruitLevelInfo
  },
  data() {
    return {
      list: []
    }
  },
  created() {
    this.getRecruitLevel()
  },
  methods: {
    reloadFun() {
      this.getRecruitLevel()
    },
    addRecruitLevel() {
      this.$refs['info'].dialogVisible = true
      this.$refs['info'].title = '新增'
      this.$refs['info'].form = {
        level: '',
        deposit: '',
        down_payment: '',
        final_payment: ''
      }
    },
    resetRecruitLevel(row) {
      this.$refs['info'].dialogVisible = true
      this.$refs['info'].title = '修改'
      this.$refs['info'].form = row
    },
    getRecruitLevel() {
      getRecruitLevelApi().then(res => {
        if (res.code === 200) {
          this.list = res.list
        }
      })
    },
    deleteRecruitLevel(row) {
      this.$confirm('此操作将删除招聘等级为 [' + row.level + ']的数据，是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const data = {
          id: row.id
        }
        deleteRecruitLevelApi(data).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getRecruitLevel()
          }
        })
      }).catch(() => {
        // this.$message({
        //   type: 'info',
        //   message: '已取消删除'
        // })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
    &-container {
        margin: 30px;
    }
    &-text {
        font-size: 30px;
        line-height: 46px;
    }
}
</style>
